﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.IO;

namespace FlickrMe.Upload
{
    /*
     * Class that displays a open file dialog for image selection. 
     */
    class Browse
    {
        String selectionFilter = "Image File (*.jpg;*.gif;*.png;*.tiff) | *.jpg;*.gif;*.png;*.tiff";

        String initDir;

        String SelectionFilter
        {
            set { selectionFilter = value; }
            get { return selectionFilter; }
        }

        public void setInitialDirectory(String initDir)
        {
            this.initDir = initDir;
        }

        /*
         * Browses for a single file
         */
        public String getBrowsePath()
        {
            String[] fnames = getBrowsePath(false);

            if (fnames.Length > 0)
            {
                return fnames[0];
            } else {
                return "";
            }
        }

        /*
         * Browses for multiple fles
         */
        private String[] getBrowsePath(Boolean multi)
        {
            String[] fnames = new String[0];

            OpenFileDialog d = new OpenFileDialog();
            d.Multiselect = multi;
            d.Filter = selectionFilter;
            d.InitialDirectory = getInitDir();
            if (d.ShowDialog() == DialogResult.OK)
            {
                fnames = d.FileNames;
            }

            return fnames;
        }

        /*
        * 
        */
        public String[] getMultiBrowsePath()
        {
            return getBrowsePath(true);
        }

        

        /**
         * 
         */
        private String getInitDir()
        {
            String dir = "";

            if (initDir == null)
            {
                initDir = Path.GetDirectoryName(Directory.GetCurrentDirectory());
            }
            else
            {
                dir = initDir;
            }
            return dir;
       
        }

    }

   
}
